package de.bmuskalla.brainfuck.ui.editor.editors;

import org.eclipse.jface.text.rules.IPredicateRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedPartitionScanner;
import org.eclipse.jface.text.rules.Token;

public class BFPartitionScanner extends RuleBasedPartitionScanner {

	public final static String BF_INCREMENT_POINTER = "__bf_increment_pointer";
	public final static String BF_DECREMENT_POINTER = "__bf_decrement_pointer";
	public final static String BF_INCREMENT = "__bf_increment";
	public final static String BF_DECREMENT = "__bf_decrement";
	public final static String BF_OUTPUT = "__bf_output";
	public final static String BF_INPUT = "__bf_input";
	public final static String BF_JUMP_FORWARD = "__bf_jump_forward";
	public final static String BF_JUMP_BACKWARD = "__bf_jump_backward";
	public final static String BF_COMMENT = "__bf_comment";

	public BFPartitionScanner() {

		IToken incrementPointer = new Token(BF_INCREMENT_POINTER);
		IToken decrementPointer = new Token(BF_DECREMENT_POINTER);
		IToken increment = new Token(BF_INCREMENT);
		IToken decrement = new Token(BF_DECREMENT);
		IToken output = new Token(BF_OUTPUT);
		IToken input = new Token(BF_INPUT);
		IToken jumpForward = new Token(BF_JUMP_FORWARD);
		IToken jumpBackward = new Token(BF_JUMP_BACKWARD);
		IToken comment = new Token(BF_COMMENT);

		IPredicateRule[] rules = new IPredicateRule[9];

		rules[0] = new BFCommandWordPatternRule(">", incrementPointer);
		rules[1] = new BFCommandWordPatternRule("<", decrementPointer);
		rules[2] = new BFCommandWordPatternRule("+", increment);
		rules[3] = new BFCommandWordPatternRule("-", decrement);
		rules[4] = new BFCommandWordPatternRule(".", output);
		rules[5] = new BFCommandWordPatternRule(",", input);
		rules[6] = new BFCommandWordPatternRule("[", jumpForward);
		rules[7] = new BFCommandWordPatternRule("]", jumpBackward);
		rules[7] = new BFCommandWordPatternRule("]", jumpBackward);
		rules[8] = new BFCommentRule(comment);

		setPredicateRules(rules);
	}
}
